<script>
	import util from '@/utils/util.js';
	import { mapMutations } from 'vuex'
	export default {
		data() {
		    return {
		      barHeight: 0
		    }
		},
		  
		onLaunch: function() {
			let data = [];
			if(!util.getStorageSync('songSheet')){
				util.setStorageSync('songSheet', JSON.stringify(data));
			}
			
			if(!util.getStorageSync('collection')){
				util.setStorageSync('collection', JSON.stringify(data));
			}
			
			if(!util.getStorageSync('songSheetList')){
				util.setStorageSync('songSheetList', JSON.stringify(data));
			}
			
			if(!util.getStorageSync('playModel')){
				util.setStorageSync('playModel', JSON.stringify(1));
			}else{
				this.setPlayStatus(util.getStorageSync('playModel'))
			}
			
			if(!util.getStorageSync('playList')){
				util.setStorageSync('playList', JSON.stringify(data));
			}else{
				let value = JSON.parse(util.getStorageSync('playList'));
				value.some((val, key) => {
					if(val.isPlay){
						this.setPlaying(val);
						this.setPlayingIndex(key);
					}
				});
			}
			
			if(!util.getStorageSync('songSheetPlayList')){
				util.setStorageSync('songSheetPlayList', JSON.stringify(data));
			}else{
				let value = JSON.parse(util.getStorageSync('songSheetPlayList'));
				value.some((val, key) => {
					if(val.isPlay){
						this.setPlaying(val);
						this.setPlayingIndex(key);
					}
				});
			}
			
			if(!util.getStorageSync('songSheetInfo')){
				util.setStorageSync('songSheetInfo', JSON.stringify(data));
			}
		},
		
		onShow: function() {

		},
		
		methods:{
			...mapMutations({
				setPlaying: 'SET_PLAYING',
				setPlayingIndex: 'SET_PLAYING_INDEX',
				setPlayStatus: 'SET_PLAY_STATUS'
			 }),
			 
			 songLyric(id){
			 	var lrcObj = {};
			 	songLyric({id: id}).then(data => {
			 		var lyricArr = data.lrc.lyric.split('[').slice(1);
			 		lyricArr.forEach(item => {
			 			var arr = item.split(']');
			 			// 时间换算成秒
			 			var m = parseInt(arr[0].split(':')[0])
			 			var s = parseInt(arr[0].split(':')[1])
			 			arr[0] = m * 60 + s;
			 			if (arr[1] != '\n') { // 去除歌词中的换行符
			 				lrcObj[arr[0]] = arr[1];
			 			}
			 			
			 		});
			 		return lrcObj;
			 	});
			 }
		},
		
		onHide: function() {

		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import '@/uni_modules/uni-scss/index.scss';
	@import '@/static/css/common.css';
	
	/* #ifndef APP-NVUE */
	@import '@/static/customicons.css';
	
	// 设置整个项目的背景色
	page {
		background-color: #f5f5f5;
	}

	/* #endif */
	.example-info {
		font-size: 14px;
		color: #333;
		padding: 10px;
	}
</style>
